package org.jeecg.modules.haili.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.modules.haili.entity.insurance.NewOrder;
import org.jeecg.modules.haili.entity.insurance.OriginInsOrder;
import org.jeecg.modules.haili.mapper.NewOrderMapper;
import org.jeecg.modules.haili.service.NewOrderService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

@Service
public class NewOrderServiceImpl extends ServiceImpl<NewOrderMapper, NewOrder> implements NewOrderService {

    private Logger logger = LoggerFactory.getLogger(NewOrderServiceImpl.class);

    @Override
    public void insertOriginOrder(OriginInsOrder order) {
        logger.info("update to mysql or{}", JSONObject.toJSONString(order));

        NewOrder newOrder = this.baseMapper.selectById(order.getId());
        if (newOrder != null) {
            BeanUtil.copyProperties(order, newOrder);
            this.baseMapper.updateById(newOrder);
        } else {
            newOrder = new NewOrder();
            BeanUtil.copyProperties(order, newOrder);
            this.baseMapper.insert(newOrder);
        }

    }
}
